package com.zyx.springmvcmsb.response.converter;

import com.zyx.springmvcmsb.response.bean.User;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * @author zyx
 * @since 2021/10/4 15:03
 */
@Component
public class MyConverter implements Converter<String, User> {
    @Override
    public User convert(String user) {
        User newuser = null;
        if (!"".equals(user) && user.split("-").length == 4){
            newuser = new User();
            String[] strings = user.split("-");
            newuser.setId(Integer.parseInt(strings[0]));
            newuser.setName(strings[1]);
            newuser.setAge(Integer.parseInt(strings[2]));
            newuser.setPassword(strings[3]);
        }
        return newuser;
    }
}
